package com.facebook.datasource;

public abstract class BaseDataSubscriber<T> implements DataSubscriber<T> {
    public BaseDataSubscriber() {

    }

    public final void onNewResult(AbstractDataSource<T> dataSource) {
        boolean isFinished = dataSource.isFinished();
        try {
            this.onNewResultImpl(dataSource);
        } finally {
            if (isFinished) {
                dataSource.close();
            }
        }
    }

    public final void onFailure(AbstractDataSource<T> dataSource) {
        try {
            this.onFailureImpl(dataSource);
        } finally {
            dataSource.close();
        }
    }

    public abstract void onNewResultImpl(AbstractDataSource<T> dataSource);

    public abstract void onFailureImpl(AbstractDataSource<T> dataSource);
}

